package com.hevs.samplewebapp.shared.security;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * @author Arnaud Durand, Matthias Hurni creation : 14.03.12
 * 
 *         Goal: Credential level that is sent back after login
 * 
 */
public enum CredentialLevel {
	/**
	 * No authentication
	 */
	NONE(0, "None"),
	USER(1, "User"),
	DOCTOR(2, "Doctor"),
	ADMINISTRATOR(3, "Administrator");

	private final int val;
	private final String name;
	private static final Map<Integer, CredentialLevel> lookup = new HashMap<Integer, CredentialLevel>();

	static {
		for (CredentialLevel c : EnumSet.allOf(CredentialLevel.class))
			lookup.put(c.getVal(), c);
	}

	private CredentialLevel(int val, String name) {
		this.val = val;
		this.name = name;
	}

	/**
	 * Returns the integer value of this level (greater value, more permissions)
	 */
	public int getVal() {
		return val;
	}

	/**
	 * Returns the name of this level
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the size of the enum
	 */
	public static int getSize() {
		return CredentialLevel.values().length;
	}

	/**
	 * Returns the CredentialLevel Enum
	 */
	public static CredentialLevel get(int val) {
		return lookup.get(val);
	}

	public String toString() {
		return name;
	}
}
